package com.suarte.core;

import com.suarte.utils.Persistent;
import org.appfuse.model.BaseObject;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.math.BigDecimal;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;

/**
 * @date   Dec 30, 2010
 * @author Ggutierrez
 */
@Entity @Table(name="sa_products")
public class Product extends BaseObject implements Persistent {
    private Long id;
    private String code;
    private String description;
    private BigDecimal price;
    private BigDecimal minPrice;
    private BigDecimal maxPrice;
    private Resolution resolution;
    private WorkType workType;
    private UnitMeasure unitMeasure;
    private Float measure;

    public Product() {
    }

    @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="PRODUCT_SEQ")
    @SequenceGenerator(name="PRODUCT_SEQ", sequenceName="PRODUCT_SEQ",allocationSize=1)
    public Long getId() {
        return id;
    }

    @Column (name="code", length=15)
    public String getCode(){
        return code;
    }

    @Column(name="description", length=100)
    public String getDescription() {
        return description;
    }

    @Column(name="price")
    public BigDecimal getPrice() {
        return price;
    }

    @Column(name="min_price")
    public BigDecimal getMinPrice() {
        return minPrice;
    }

    @Column(name="max_price")
    public BigDecimal getMaxPrice() {
        return maxPrice;
    }

    @ManyToOne
    @JoinColumn(name = "resolution_id")
    public Resolution getResolution() {
        return resolution;
    }

    @ManyToOne
    @JoinColumn(name = "work_type_id")
    public WorkType getWorkType() {
        return workType;
    }

    @ManyToOne
    @JoinColumn(name = "unit_measure_id")
    public UnitMeasure getUnitMeasure() {
        return unitMeasure;
    }

    @Column(name="measure")
    public Float getMeasure() {
        return measure;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setCode(String code){
        this.code = code;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public void setMinPrice(BigDecimal minPrice) {
        this.minPrice = minPrice;
    }

    public void setMaxPrice(BigDecimal maxPrice) {
        this.maxPrice = maxPrice;
    }

    public void setResolution(Resolution resolution) {
        this.resolution = resolution;
    }

    public void setWorkType(WorkType workType) {
        this.workType = workType;
    }

    public void setUnitMeasure(UnitMeasure unitMeasure) {
        this.unitMeasure = unitMeasure;
    }

    public void setMeasure(Float measure) {
        this.measure = measure;
    }

    @Override
    public String toString() {
        return description;
    }

    @Override
    public boolean equals(Object other) {
        if(other == this){
            return true;
        }
        if(!(other instanceof Product)){
            return false;
        }
        Product _i = (Product)other;
        return id.equals(_i.id);
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }
}
